package secondriver.springsubway.example.rpv.demo;


import secondriver.springsubway.example.rpv.ErrorDesc;
import secondriver.springsubway.example.rpv.ParameterValidatorHelper;
import secondriver.springsubway.example.rpv.ParameterValidatorResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by ZhangXiao on 2015/6/11.
 */
@WebServlet(name = "userSerlvet", urlPatterns = {"/user"})
public class UserServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ParameterValidatorResult result = ParameterValidatorHelper.annotationParameterValidator(UserParameter.class,
                request);
        StringBuffer sb = new StringBuffer("Hello<br/>");
        if (result.hasInvalidParameter()) {
            List<ErrorDesc> errorDescList = result.errorDesc();

            for (ErrorDesc errorDesc : errorDescList) {
                sb.append("errorCode:").append(errorDesc.getErrorCode()).append(",message:").append(errorDesc.getMessage
                        ()).append(",");

            }
        }
        response.setCharacterEncoding("UTF-8");
        response.getWriter().print(sb.toString());
    }
}